package com.ylb.controller;

import com.ylb.entity.User;
import com.ylb.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * @author: ylb
 * @create: 2021.3.22
 */
@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @GetMapping("/userlist")
    public List<User> findAllUsers(){
        return userMapper.findUsers();
    }

    @GetMapping("/save")
    public String addUser(){
        User user = new User();
        user.setUsername("ababa"+new Random().nextInt());
        user.setPassword("123");
        user.setAge(14);
        user.setPhone(12306);
        user.setBirthday(new Date());
        userMapper.addUser(user);
        return "success";
    }
}
